/******************************************************************************
 cnome: A C++ source "genes" discover. :-)

 See more details at:

   http://www.codeplex.com/cnome

 The original author site is at: http://www.alexandre-barbosa.com/

 Copyright (c) 2008 Alexandre Barbosa.
 Distributed under the MIT License. (See accompanying file LICENSE-MIT.txt 
 or at http://www.codeplex.com/cnome/license)
 ******************************************************************************/

#ifndef DIRECTIVE_RTP_H
#define DIRECTIVE_RTP_H

#include "directive_base.h"
#include "variables.h"

namespace cnome { namespace directive {

    struct rtp_parser_gen;
 
    template <typename ParserT>
    struct rtp
    :   public boost::spirit::classic::unary<ParserT, boost::spirit::classic::parser<rtp<ParserT> > > 
    {
        typedef rtp<ParserT>                    self_t;
        typedef boost::spirit::classic::unary_parser_category           parser_category_t;
        typedef rtp_parser_gen                  parser_generator_t;
        typedef boost::spirit::classic::unary<ParserT, boost::spirit::classic::parser<self_t> > base_t;

        static lstScopeT l_tmplPrms;
        static scopeT tmplPrms;

        rtp(ParserT const& p)
        : base_t(p) {}

        template <typename ScannerT>
        typename boost::spirit::classic::parser_result<self_t, ScannerT>::type
        parse(ScannerT const& scan) const
        {
            typedef typename boost::spirit::classic::parser_result<self_t, ScannerT>::type result_t;
            return impl::drt_parser_parse<result_t>
                (*this, scan, scan);
        }

        const char* MyName() const { return "rtp"; }

        template <typename ScannerT>
        inline void
        deriv_action_before_parse(
            ScannerT const& scan)
        {
            var::l_tmplPrms.push_back(var::tmplPrms);
        }

        template <typename ScannerT>
        inline void
        deriv_action_after_parse(
            ScannerT const& scan) 
        {
            var::tmplPrms=var::l_tmplPrms.back();
            var::l_tmplPrms.pop_back();
        }

    };

    template <typename ParserT>
    lstScopeT rtp<ParserT>::l_tmplPrms;

    template <typename ParserT>
    scopeT rtp<ParserT>::tmplPrms;

    //////////////////////////////////
    const drt_parser_gen<rtp> remain_tmplprm_d = drt_parser_gen<rtp>();

}} // namespace cnome { namespace directive {

#endif  // DIRECTIVE_RTP_H
